package com.woniu.humanresource.service.impl;


import com.woniu.humanresource.dao.JobRelationDao;
import com.woniu.humanresource.entity.JobRelation;
import com.woniu.humanresource.entity.PageBean;
import com.woniu.humanresource.service.JobRelationService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class JobRelationServiceImpl implements JobRelationService {

    @Resource
    JobRelationDao jobRelationDao;


    @Override
    public void insertJobRelation(JobRelation jobRelation) {
        jobRelationDao.insertJobRelation(jobRelation);
    }

    @Override
    public PageBean<JobRelation> getAllJobRelation(int pageIndex, int pageSize) {
        // 查询所有职位关系集合
        List<JobRelation> allJobRelation = jobRelationDao.selectAllJobRelation(pageIndex, pageSize);
        // 封装为pageBean对象
        PageBean<JobRelation> allJobRelationpageBean = new PageBean<>();
        allJobRelationpageBean.setBeanList(allJobRelation);
        allJobRelationpageBean.setPageIndex(pageIndex);
        allJobRelationpageBean.setPageSize(pageSize);
        allJobRelationpageBean.setBeginEnd();
        allJobRelationpageBean.setTotalRecord(jobRelationDao.selectAllJobRelationcounts());
        return allJobRelationpageBean;
    }

    @Override
    public void updateJobRelation(JobRelation jobRelation, String position) {
        jobRelationDao.updateJobRelation(jobRelation, position);
    }

    @Override
    public void deleteJobRelationByPosition(String position) {
        jobRelationDao.deleteJobRelationByPosition(position);
    }

    @Override
    public List<JobRelation> selectJobRelatinoByPosition(String position) {
        List<JobRelation> jobRelationsByPosition = jobRelationDao.selectJobRelationByPosition(position);
        return jobRelationsByPosition;
    }

    @Override
    public void deleteApplyByPosition(String position) {
        jobRelationDao.deleteApplyByPosition(position);
    }

    @Override
    public PageBean<JobRelation> getJobRelation(JobRelation jobRelation, int pageIndex, int pageSize) {
        // 条件查询
        List<JobRelation> jobRelationList = jobRelationDao.selectJobRelation(jobRelation,pageIndex, pageSize);
        // 封装为pageBean对象
        PageBean<JobRelation> jobRelationpageBean = new PageBean<>();
        jobRelationpageBean.setBeanList(jobRelationList);
        jobRelationpageBean.setPageIndex(pageIndex);
        jobRelationpageBean.setPageSize(pageSize);
        jobRelationpageBean.setBeginEnd();
        jobRelationpageBean.setTotalRecord(jobRelationDao.selectJobRelationCounts(jobRelation));
        return jobRelationpageBean;
    }
}
